﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

namespace BtoBSWT315.User
{
    public partial class Edit_Job : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("../Default.aspx");
            }
            if (!IsPostBack)
            {
                EditDataBind();
            }

        }

        private void EditDataBind()
        {
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            int ID = Convert.ToInt32(Request.QueryString["ID"].ToString());

            //定义所需SQL语句
            string sql = "select * from job where id=" + ID;
            OleDbDataReader dr = classdb.Getdr(sql);
            if (dr.Read())
            {
                showname.Text = dr["showname"].ToString();                     
                address.Text = dr["address"].ToString();
                country.Text = dr["country"].ToString();
                linkman.Text = dr["linkman"].ToString();
                phone.Text = dr["phone"].ToString();
                web.Text = dr["web"].ToString();
                content.Text = dr["content"].ToString();
                zrs.Text = dr["zrs"].ToString();
                company.Text = dr["company"].ToString();
                mail.Text = dr["mail"].ToString();
                period.SelectedValue = dr["period"].ToString();
                type.SelectedValue = dr["type"].ToString();              
            }
            dr.Close();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();

            int ID = Convert.ToInt32(Request.QueryString["ID"]);

            string insertSql = "update job set showname='"+showname.Text.Trim()+"', type='"+type.SelectedValue.Trim()+"',period='"+ period.SelectedValue+"',content='"+content.Text.Trim()+"', linkman='"+ linkman.Text.Trim()+"',zrs='" + zrs.Text+"',company='"+company.Text+"',address='"+address.Text+"',phone='"+phone.Text+"' ,web='"+web.Text+"' ,mail='"+mail.Text+"',country='"+country.Text.Trim()+"' where id="+ID;
             
            if (classdb.GetNonResult(insertSql) != 0)
            {
                Response.Write("<script>alert('操作成功，请刷新页面！');</script>");
                Response.Write("<script>history.go(-2);</script>");
                Response.End();           
            }
            else
            {
                Response.Write("<script>alert('操作失败！请重新填写。');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }
        }
    }
}